All Questions
19 questions
2votes
3answers
1kviews
Find the 'n' most frequent words in a text, aka word frequency
I'm doing freeCodeCamp's Coding Interview Prep to improve my JavaScript skills. This challenge is called "Word Frequency", and is based on the Rosetta Code's entry of the same name. The ...
-1votes
1answer
343views
Hackerrank Gridland Metro - using Interval Cover Solution [closed]
Hi there I was hoping to get a better grasp of greddy algorithms while trying to solve this problem: Hackerrank: Gridland Metro and I was trying to apply an algorithm where each grid could be ...
1vote
2answers
1kviews
Calculate transaction balances and find duplicate transactions
In an interview I was asked to solve two JavaScript questions. I thought I did pretty well because I: Covered the edge cases Wrote comprehensive tests Documented the code using jsdoc The interviewer ...
3votes
1answer
580views
Find the largest product of an array
This task is taken from www.interviewbit.com Given an array of integers, return the highest product possible by multiplying 3 numbers from the array Input: ...
6votes
2answers
427views
Find matching dictionary words given a Scrabble tray
This is a question I was asked in an interview, below is a cleaned-up copy of the answer I gave. Apparently this answer was not satisfactory. How can it be improved? Question: Given a dictionary of ...
6votes
2answers
305views
Find top two clothing sizes in the array
I was recently asked this question in an interview. Here is the solution I came up with. Please let know if I could have done this differently or in a more efficient manner. The question is as ...
5votes
3answers
2kviews
LeetCode 189 - Rotate Array
I have a working solution for this problem that was accepted in LeetCode: Given an array, rotate the array to the right by k steps, where k is non-negative." ...
6votes
2answers
3kviews
Minimum swaps algorithm terminated due to timeout
I have been trying to solve this question. Given an unordered array consisting of consecutive integers [1, 2, 3, …, n], find the minimum number of two-element swaps to sort the array. I was able ...
5votes
3answers
126views
Array's reverse vs simple arithmethic
I was asked to print numbers from 100 to 1 in a for loop with the index starting from 1. I came up with this solution: ...
7votes
2answers
8kviews
Find the intersect area of two overlapping rectangles
This is my solution to find the coordinates of 2 overlapped rectangles implemented in JavaScript. Each rectangle is represented by 2 points, each with 2 (x,y) coordinates. Can this code be improved? ...
1vote
1answer
915views
Hackerrank "Queues: A Tale of Two Stacks" Javascript Solution
Here is the original problem, and below is my solution (passing). It's asking to implement a queue with 2 stacks, which means I cannot simply use Array.shift. I wonder if the solution can be improved. ...
6votes
1answer
2kviews
Text justification program
I'm looking for code review comments for text justification problem described here. Problem: Given an array of words and a length L, format the text such that each line has exactly L characters and ...
2votes
1answer
4kviews
Left rotation arrays algorithm
This is my solution to the common 'Array Rotation' algorithm. As I am currently practicing for coding interviews, I want to make sure that my code in fact valid for coding interview scenarios. Would I ...
6votes
3answers
879views
Flatten an array
I have got this interview question which has asked me to write a production level code which flattens the arbitrary nested array of arrays. Code ...
2votes
3answers
469views
Minimum element in a sorted rotated array
A sorted array [0,1,2,3,4,5] when rotated n times (3 times in this case) becomes [3,4,5,0,1,2], meaning elements in the front move to the end. The code below finds the minimum element in this array, ...